/*
* @(#)OutputDataToApplet.java
*
* Copyright (c) 2004 DCIVision Ltd
* All rights reserved.
*
* This software is the confidential and proprietary information of DCIVision
* Ltd ("Confidential Information").  You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with DCIVision Ltd.
*/

package com.dcivision.workflow.applet;


// IO related imports
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.ObjectOutputStream;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dcivision.dms.dao.DmsRootDAObject;
import com.dcivision.form.bean.FormElement;
import com.dcivision.form.bean.FormElementType;
import com.dcivision.form.bean.FormPage;
import com.dcivision.form.bean.FormRecord;
import com.dcivision.form.bean.MtmFormPageFormSection;
import com.dcivision.form.bean.MtmFormSectionFormElement;
import com.dcivision.form.dao.FormElementDAObject;
import com.dcivision.form.dao.FormGroupDAObject;
import com.dcivision.form.dao.FormPageDAObject;
import com.dcivision.form.dao.FormRecordDAObject;
import com.dcivision.form.dao.FormSectionDAObject;
import com.dcivision.form.dao.MtmFormPageFormSectionDAObject;
import com.dcivision.form.dao.MtmFormSectionFormElementDAObject;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.MessageResourcesFactory;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.dao.SysUserDefinedIndexDAObject;
import com.dcivision.setup.dao.SetupOptionWorkflowCategoryDAObject;
import com.dcivision.user.dao.UserGroupDAObject;
import com.dcivision.user.dao.UserRecordDAObject;
import com.dcivision.user.dao.UserRoleDAObject;
import com.dcivision.workflow.bean.MtmWorkflowInterruptUserActor;
import com.dcivision.workflow.bean.MtmWorkflowRecordObjectLink;
import com.dcivision.workflow.bean.MtmWorkflowStepUserActor;
import com.dcivision.workflow.bean.WorkflowAction;
import com.dcivision.workflow.bean.WorkflowRecord;
import com.dcivision.workflow.bean.WorkflowStep;
import com.dcivision.workflow.bean.WorkflowStepFormEquat;
import com.dcivision.workflow.bean.WorkflowStepRoute;
import com.dcivision.workflow.core.AutomaticTaskFactory;
import com.dcivision.workflow.core.SystemWorkflowConstant;
import com.dcivision.workflow.core.WorkflowProcessor;
import com.dcivision.workflow.core.WorkflowRetrievalManager;
import com.dcivision.workflow.dao.MtmWorkflowInterruptUserActorDAObject;
import com.dcivision.workflow.dao.MtmWorkflowRecordObjectLinkDAObject;
import com.dcivision.workflow.dao.MtmWorkflowStepWorkflowStepDAObject;
import com.dcivision.workflow.dao.WorkflowActionDAObject;
import com.dcivision.workflow.dao.WorkflowGroupDAObject;
import com.dcivision.workflow.dao.WorkflowRecordDAObject;
import com.dcivision.workflow.dao.WorkflowStepDAObject;
import com.dcivision.workflow.dao.WorkflowStepFormEquatDAObject;
import com.dcivision.workflow.dao.WorkflowStepRouteDAObject;


/**
 * <p>Class Name:       OutputDataToApplet.java    </p>
 * <p>Description:      get some list data and send to applet</p>
 *
 * @author           Beyond Qu
 * @company          DCIVision Limited
 * @creation date    31/08/2004
 * @version          $Revision: 1.18 $
 */

public class OutputDataToApplet{

  public static final String REVISION = "$Revision: 1.18 $";

    private String dataType = "";
    private Integer workflowRecordID = null;

    private SessionContainer sessionContainer;
    private Connection conn;
    private HttpServletRequest request;
    
    
    /**
     * OutputDataToApplet
     * 
     * This function construct OutputDataToApplet class
     *
     * @param sessionContainer
     * @param conn
     * @param dataType   
     * @param workflowRecordID
     */
    public OutputDataToApplet(HttpServletRequest request,SessionContainer sessionContainer, Connection conn ,String dataType,
            Integer workflowRecordID) {
        this.sessionContainer = sessionContainer;
        this.conn = conn;
        this.request = request;
        this.dataType = dataType;
        this.workflowRecordID = workflowRecordID ;
    }

    /**
     * sendResponseToApplet
     * 
     * This function will send the some paraDM's data  to the applet
     *
     * @param response 
     *
     */
    protected void sendResponseToApplet(HttpServletResponse response) throws Exception {
        // create a reference to ObjectOutputStream class
        ObjectOutputStream outputToApplet = null;         
    
        List workflowGroupList = null;
        List workflowRecordList = null;
        List interruptworkflowList = null;
        
        List workflowStepRecordList = null;        
        
        List workflowCategoryList = null;
        List workflowBindList = null;
        List bindWithSelectList = null;
       
        List userRecordList = null;
        List userGroupList = null;    
        List userRoleList = null;
        String[][] specialActor = null;
        List formSectionList = null;
        List stepList = null;

        
        if(dataType == null || "".equals(dataType)){
            System.out.println("===============AppletMiddleware dateType is null===============");
            return ;    
        }        
        
        try {
            
            if(sessionContainer == null || conn == null){
                throw new Exception();    
            }
            
            if(this.sessionContainer.getUserRecord() == null){
              throw new Exception();
            }        

            // create ObjectOutputStream object
            outputToApplet = new ObjectOutputStream(response.getOutputStream());
            
            // write obj to outputToApplet object            
            if("GET_RECORDGROUP".equals(dataType)){
                workflowGroupList  = getWorkflowGroupList();
                workflowRecordList = getWorkflowRecordList();                                   
                outputToApplet.writeObject(workflowGroupList);     
                outputToApplet.writeObject(workflowRecordList);
            }else if("GET_CATEGORYGROUP".equals(dataType)){
                workflowCategoryList = getWorkflowCategoryList();
                workflowGroupList  = getWorkflowGroupList();
                interruptworkflowList  = getInterruptworkflowList();
                outputToApplet.writeObject(workflowGroupList);     
                outputToApplet.writeObject(workflowCategoryList);
                outputToApplet.writeObject(interruptworkflowList);
                
            }else if("GET_WORKFLOWSTEP".equals(dataType)){                
                workflowStepRecordList = getWorkflowStepByRecordID(workflowRecordID);
                outputToApplet.writeObject(workflowStepRecordList);                   
            }else if("GET_BINDWITH".equals(dataType)){
              workflowBindList = getWorkflowBindList(new Integer(request.getParameter("categoryID")));
              bindWithSelectList = getBindWithSelectList(workflowRecordID);
              outputToApplet.writeObject(workflowBindList);
              outputToApplet.writeObject(bindWithSelectList);
            }else if("GET_USERINFO".equals(dataType)){
              userRecordList = getUserRecordList();
              userGroupList = getUserGroupList();
              userRoleList = getUserRoleList();
              specialActor = getSpecialActor();
              formSectionList = getformSectionList();
              stepList = getStepList();
              List autoTaskTypeList = getAutoTaskTypeList();
              outputToApplet.writeObject(userRecordList);
              outputToApplet.writeObject(userGroupList);
              outputToApplet.writeObject(userRoleList);
              outputToApplet.writeObject(specialActor);
              outputToApplet.writeObject(formSectionList);
              outputToApplet.writeObject(stepList);
              outputToApplet.writeObject(autoTaskTypeList);
            }else if("GET_STEPINFO".equals(dataType)){
               String maxStepSeq = getNextStepSeq();
               Object stepInfo = getStepInfoByWorkflowIDAndStepSeq();
               outputToApplet.writeObject(maxStepSeq);
               outputToApplet.writeObject(stepInfo);
            }else if("GET_WORKFLOWCHART".equals(dataType)){
                String  workflowChart = getWorkflowChartByRecordID();
              outputToApplet.writeObject(workflowChart);   
            }else if("GET_WORKFLOWRECORD".equals(dataType)){
              Object workflowrecord = getWorkflowRecord();
              outputToApplet.writeObject(workflowrecord);
            }else if("BUILD_TREE".equals(dataType)){
              List workflowSteps = getWorkflowStepByRecordID(workflowRecordID);
              outputToApplet.writeObject(workflowSteps);
              List StepConnections = getStepConnectionsByRecordID(workflowRecordID);
              outputToApplet.writeObject(StepConnections);
            }else if("STEP_ROUTE".equals(dataType)){
              String routeName = getRouteNameByStepIDAndSeq();
              outputToApplet.writeObject(routeName);
            }else if("GET_FORM".equals(dataType)){
              List formElementList = new ArrayList();
              List formRecordList = new ArrayList();
              getFormList(formElementList,formRecordList);
              outputToApplet.writeObject(formElementList);
              outputToApplet.writeObject(formRecordList);
            }else if("GET_FORMELEMENT".equals(dataType)){
              List formElementList = new ArrayList();
              formElementList = getFormElementList();
              outputToApplet.writeObject(formElementList);
            }else if("WORKFLOW_ACTION".equals(dataType)){
              String[] actionRouteLable = getActionRouteLable();
              outputToApplet.writeObject(actionRouteLable);
            }else if("RESOURCE".equals(dataType)){
              String[] resouce = getResouce();
              outputToApplet.writeObject(resouce);
            }else if("GET_RESOURCEBYCODE".equals(dataType)){
              String resouce = getResouceByCode();
              outputToApplet.writeObject(resouce);
            }                 
            // close and flush the ObjectOutputStream
            outputToApplet.flush();
            outputToApplet.close();
        } catch (Exception e) {
              throw e;                
                // close and flush the ObjectOutputStream

        }
    }

    /**
     * getWorkflowGroupList
     * 
     * get workflow group list
     *
     */    
    private List getWorkflowGroupList() throws Exception {
        List tempList = new ArrayList();
        WorkflowGroupDAObject wfgDAObj = new WorkflowGroupDAObject (sessionContainer,conn);
        try{
            tempList = wfgDAObj.getFullList();
        }catch(Exception e){            
            throw new Exception(e);
        }                
        return tempList;
    }
    
    /**
     * getWorkflowGroupList
     * 
     * get workflow group list
     *
     */    
    private List getInterruptworkflowList() throws Exception {
      SetupOptionWorkflowCategoryDAObject setupOptionWorkflowCategoryDAO = new SetupOptionWorkflowCategoryDAObject(sessionContainer,conn);
      WorkflowRecordDAObject workflowRecordDAO = new WorkflowRecordDAObject(sessionContainer,conn);
      List workflowRecordList = new ArrayList();
      try {
        List fullWorkflowRecordList = workflowRecordDAO.getLastBySysWorkflowCategoryID(new Integer(SystemWorkflowConstant.SUB_WORKFLOW_INTERRUPT));
        for (int i = 0; !Utility.isEmpty(fullWorkflowRecordList) && i < fullWorkflowRecordList.size(); i++) {
          WorkflowRecord workflowRecord =  (WorkflowRecord)fullWorkflowRecordList.get(i);
          String[] aOption = new String[2];
          aOption[1] = workflowRecord.getWorkflowCode() + "(" + (workflowRecord.getDescription()==null?"":workflowRecord.getDescription()) + "[" + workflowRecord.getWorkflowVersion() + "]" + ")";
          aOption[0] = workflowRecord.getID().toString();
          workflowRecordList.add(aOption);
        }
      } catch(ApplicationException ex){
        ex.printStackTrace();
      }
      return (workflowRecordList);
    }

    /**
     * getWorkflowRecordList
     * 
     * get workflow record list
     *
     */    
    private List getWorkflowRecordList() throws Exception {
        List tempList = new ArrayList();
        WorkflowRecordDAObject wfrDAObj = new WorkflowRecordDAObject (sessionContainer,conn);
        try{
            tempList = wfrDAObj.getFullList();
        }catch(Exception e){            
            throw new Exception(e);        
        }
                
        return tempList;
    }    

    /**
     * getWorkflowCategoryList
     * 
     * get workflow category list
     *
     */
    private List getWorkflowCategoryList() throws Exception {
        List tempList = new ArrayList();
        SetupOptionWorkflowCategoryDAObject wfcDAObj = new SetupOptionWorkflowCategoryDAObject (sessionContainer,conn);
        try{
            tempList = wfcDAObj.getFullList();
        }catch(Exception e){            
            throw new Exception(e);        
        }
                
        return tempList;
    }        

    /**
     * getWorkflowStepList
     * 
     * get workflow step list
     * 
     * @param workflowRecordID 
     */
    private List getWorkflowStepByRecordID(Integer workflowRecordID) throws Exception {
        List tempList = new ArrayList();
        WorkflowStepDAObject workflowStepDAObject = new WorkflowStepDAObject (sessionContainer,conn);
        try{
            if (workflowRecordID != null)
                tempList = workflowStepDAObject.getListByWorkflowRecordID(workflowRecordID);            
        }catch(Exception e){            
            throw new Exception(e);        
        }                
        return tempList;
    }
    
    /**
     * getWorkflowStepList
     * 
     * get workflow step list
     * 
     * @param workflowRecordID 
     */
    private List getStepConnectionsByRecordID(Integer workflowRecordID) throws Exception {
        List tempList = new ArrayList();
        MtmWorkflowStepWorkflowStepDAObject workflowStepStepDAObject = new MtmWorkflowStepWorkflowStepDAObject (sessionContainer,conn);
        try{
            if (workflowRecordID != null)
                tempList = workflowStepStepDAObject.getListByWorkflowID(workflowRecordID);            
        }catch(Exception e){            
            throw new Exception(e);        
        }                
        return tempList;
    }
    
    private List getUserRecordList(){
      List tempList = new ArrayList();
      try{
        UserRecordDAObject userRecordDAObject = new UserRecordDAObject(sessionContainer,conn);
        tempList = userRecordDAObject.getFullList();
      }catch(Exception e){                  
    } 
      return tempList;
      
    }
    
    private List getUserGroupList(){
      List tempList = new ArrayList();
      try{
        UserGroupDAObject userGroupDAObject = new UserGroupDAObject(sessionContainer,conn);
        tempList = userGroupDAObject.getFullList();
      }catch(Exception e){                    
    } 
      return tempList;      
    }
    
    private List getUserRoleList(){
      List tempList = new ArrayList();
      try{
        UserRoleDAObject userRoleDAObject = new UserRoleDAObject(sessionContainer,conn);
        tempList = userRoleDAObject.getFullList();
      }catch(Exception e){            
        //throw new Exception(e);        
    } 
      return tempList;
      
    }
    
    private String[][] getSpecialActor(){
      String[][] ACTOR_TYPE_MAP;
      Locale locale = sessionContainer.getSessionLocale();
      try{
        String workflowRecordID = request.getParameter("workflowRecordID");
        String parentStepID = request.getParameter("parentStepID");
        WorkflowRetrievalManager retrievalManager = new WorkflowRetrievalManager(sessionContainer, conn);
        
        List parentStepNameList = new ArrayList();
        if (!Utility.isEmpty(parentStepID)) {
          parentStepNameList = retrievalManager.getSuperStepNameListByWorkflowStepID(new Integer(parentStepID));
        }
        ACTOR_TYPE_MAP = new String[parentStepNameList.size() + 4][2];
        ACTOR_TYPE_MAP[0][0] = MessageResourcesFactory.getMessage(locale, "workflow.label.submitter");
        ACTOR_TYPE_MAP[0][1] = MtmWorkflowStepUserActor.ACTOR_TYPE_SUBMITTER;
        
        ACTOR_TYPE_MAP[1][0] = MessageResourcesFactory.getMessage(locale, "workflow.label.report_to");
        ACTOR_TYPE_MAP[1][1] = MtmWorkflowStepUserActor.ACTOR_TYPE_REPORT_TO;
        
//        ACTOR_TYPE_MAP[2][0] = MessageResourcesFactory.getMessage(locale, "workflow.label.previous_task_owner");
//        ACTOR_TYPE_MAP[2][1] = MtmWorkflowStepUserActor.ACTOR_TYPE_PREVIOUS_TASK_OWNER;
        
        ACTOR_TYPE_MAP[2][0] = MessageResourcesFactory.getMessage(locale, "workflow.label.previous_task_action_taker");
        ACTOR_TYPE_MAP[2][1] = MtmWorkflowStepUserActor.ACTOR_TYPE_PREVIOUS_TASK_ACTION_TAKER;
        
        ACTOR_TYPE_MAP[3][0] = MessageResourcesFactory.getMessage(locale, "workflow.label.report_to_of_previous_task");
        ACTOR_TYPE_MAP[3][1] = MtmWorkflowStepUserActor.ACTOR_TYPE_REPORT_TO_OF_PREVIOUS_TASK_ACTION_TAKER;
        
        for ( int i = 0; i < parentStepNameList.size(); i++ ) {
          String[] stepName = (String[])parentStepNameList.get(i);
          ACTOR_TYPE_MAP[i + 4][0] = stepName[1];
          ACTOR_TYPE_MAP[i + 4][1] = stepName[0]; 
        }
      }catch(Exception e){
        ACTOR_TYPE_MAP = null;
        //throw new Exception(e);        
    } 
      return ACTOR_TYPE_MAP;
      
    }
    
    private List getformSectionList(){
      List tempList = null;
      Integer workflowRecordID = TextUtility.parseIntegerObj(request.getParameter("workflowRecordID"));
      try{
        FormRecordDAObject formDAO = new FormRecordDAObject(sessionContainer, conn);
        List formList = formDAO.getWorkflowFormRecordByWorkflowID(workflowRecordID);
        Integer formID = ((FormRecord)formList.get(0)).getID();
        FormSectionDAObject formSecDAO = new FormSectionDAObject(sessionContainer, conn);
        tempList = formSecDAO.getAllSectionByFormID(formID);
      }catch(Exception e){            
        //throw new Exception(e);        
    } 
      return tempList;
      
    }
    
    private List getStepList(){
      List tempList = null;
      Integer workflowRecordID = TextUtility.parseIntegerObj(request.getParameter("workflowRecordID"));
      WorkflowStepDAObject workflowStepDAObject = new WorkflowStepDAObject (sessionContainer,conn);
      try{
        tempList = workflowStepDAObject.getListByWorkflowRecordID(workflowRecordID);
      }catch(Exception e){            
        //throw new Exception(e);        
    } 
      return tempList;
      
    }
    
    private List getAutoTaskTypeList(){
      List tempList = null;
      Integer workflowRecordID = TextUtility.parseIntegerObj(request.getParameter("workflowRecordID"));
      WorkflowRecordDAObject wfrDAObj = new WorkflowRecordDAObject (sessionContainer,conn);
      WorkflowActionDAObject workflowActionDAO = new WorkflowActionDAObject(sessionContainer,conn);  
      try{
        WorkflowRecord workflowRecord = (WorkflowRecord)wfrDAObj.getObjectByID(workflowRecordID);
        Integer workflowCategoryID = workflowRecord.getWorkflowCategoryID();
        tempList = workflowActionDAO.getListByWorkflowCategoryID(workflowCategoryID);
      }catch(Exception e){            
        //throw new Exception(e);        
      } 
      Locale locale = sessionContainer.getSessionLocale();
      for(int i=0;i<tempList.size();i++){
        WorkflowAction workflowAction = (WorkflowAction)tempList.get(i);
        String actionLable = MessageResourcesFactory.getMessage(locale, workflowAction.getActionLabel());
        workflowAction.setActionLabel(actionLable);
      }
      return tempList;
      
    }
    
    
    public String getRouteNameByStepIDAndSeq(){
      List tempList = null;
      Integer stepID = TextUtility.parseIntegerObj(request.getParameter("stepID"));
      String routeSeq = request.getParameter("routeSeq");
      String routeName = null;
      WorkflowStepDAObject workflowStepDAO = new WorkflowStepDAObject (sessionContainer,conn);
       
      WorkflowStepRouteDAObject workflowStepRouteDAO = new WorkflowStepRouteDAObject (sessionContainer,conn);
      WorkflowStepFormEquatDAObject workflowStepFormEquatDAO = new WorkflowStepFormEquatDAObject(sessionContainer,conn);
      try{
        WorkflowStep workflowStep = (WorkflowStep)workflowStepDAO.getObjectByID(stepID);
        if(WorkflowStep.ACTION_TYPE_USER_DEFINED_TASK.equals(workflowStep.getActionType())){
          tempList = workflowStepRouteDAO.getListByWorkflowStepID(stepID);
          for(int i=0;i<tempList.size();i++){
            WorkflowStepRoute workflowStepRoute =(WorkflowStepRoute)tempList.get(i);
            if(routeSeq.equals(workflowStepRoute.getRouteSeq().toString())){
              routeName = workflowStepRoute.getRouteName();
              routeName = routeSeq+AppletConstant.SPLITCHAR+"U"+AppletConstant.SPLITCHAR+routeName+"&"+routeName;
              break;
            }
          }
        } else if(WorkflowStep.ACTION_TYPE_FORM_DRIVEN.equals(workflowStep.getActionType())) {
          tempList = workflowStepFormEquatDAO.getListByWorkflowStepID(stepID);
          for(int i=0;i<tempList.size();i++){
            WorkflowStepFormEquat workflowStepFormEquat =(WorkflowStepFormEquat)tempList.get(i);
            if(Integer.parseInt(routeSeq)+1==workflowStepFormEquat.getRouteSeq().intValue()){
              routeName = workflowStepFormEquat.getRouteName();
              String formEquationValue = workflowStepFormEquat.getRouteName();
              formEquationValue+=WorkflowStepFormEquat.SPLIT_PREFIX_CHAR;
              formEquationValue+=workflowStepFormEquat.getDefaultFlag();
              formEquationValue+=WorkflowStepFormEquat.SPLIT_PREFIX_CHAR;
              formEquationValue+=workflowStepFormEquat.getOperand1();
              formEquationValue+=WorkflowStepFormEquat.SPLIT_PREFIX_CHAR;
              formEquationValue+=workflowStepFormEquat.getOperand2();
              formEquationValue+=WorkflowStepFormEquat.SPLIT_PREFIX_CHAR;
              formEquationValue+=workflowStepFormEquat.getCompare();
              formEquationValue+=WorkflowStepFormEquat.SPLIT_PREFIX_CHAR;
              formEquationValue+=workflowStepFormEquat.getFormEquation();
              formEquationValue+=WorkflowStepFormEquat.SPLIT_PREFIX_CHAR;
              formEquationValue+=workflowStepFormEquat.getOperationType();
              formEquationValue+=WorkflowStepFormEquat.SPLIT_PREFIX_CHAR;
              formEquationValue+=workflowStepFormEquat.getDateFormat();
              routeName = routeSeq.toString()+AppletConstant.SPLITCHAR+"D"+AppletConstant.SPLITCHAR+routeName+"#"+formEquationValue+"&"+routeName;
              break;
            }
          }
        } else if(WorkflowStep.ACTION_TYPE_SYSTEM_AUTO.equals(workflowStep.getActionType())) {
          Integer actionID = workflowStep.getActionID();
          WorkflowActionDAObject workflowActionDAObject = new WorkflowActionDAObject (sessionContainer,conn);
          WorkflowAction workflowAction = (WorkflowAction)workflowActionDAObject.getObjectByID(actionID);
//          String actionClassName = workflowAction.getActionClassName();
//          Class actionClass = Class.forName(actionClassName);
//          Constructor constructor = actionClass.getConstructor(new Class[]{});
          WorkflowProcessor workflowProcessor=AutomaticTaskFactory.getInstance(workflowAction);//mod by greatwall for AutomaticTask
          routeName = workflowProcessor.getLabelString(routeSeq);
          Locale locale = sessionContainer.getSessionLocale();
          routeName = MessageResourcesFactory.getMessage(locale, routeName);
          routeName = WorkflowStep.PARENT_TYPE_SINGLE+routeSeq+"&"+routeName;
          
        } else {
          String locale = request.getParameter("LOCALE");
          java.util.Locale newLocale = Utility.getLocaleByString(locale);
          routeName=MessageResourcesFactory.getMessage(newLocale, "workflow.label.step_status_G");
          routeName = WorkflowStep.PARENT_TYPE_SINGLE+routeSeq+"&"+routeName;
        }
      }catch(Exception e){            
        //throw e;        
      } 
      return routeName;      
    }
    
    private List getWorkflowBindList(Integer categoryID) throws Exception {
      List tempList = new ArrayList();
      WorkflowStepDAObject workflowStepDAObject = new WorkflowStepDAObject (sessionContainer,conn);
      try{
        int workflowCategoryID = categoryID.intValue();
        if (workflowCategoryID == Integer.parseInt(SystemWorkflowConstant.DMS_CREATE_PUBLIC_DOCUMENT) || workflowCategoryID == Integer.parseInt(SystemWorkflowConstant.DMS_CREATE_SCANNED_DOCUMENT)) { //* public folder
          DmsRootDAObject rootDAO = new DmsRootDAObject(sessionContainer, conn);
          List rootList = rootDAO.getAllPublicRootList();
          return rootList;
        } else if (workflowCategoryID == Integer.parseInt(SystemWorkflowConstant.DMS_CREATE_PUBLIC_UDF_DOCUMENT) || workflowCategoryID == Integer.parseInt(SystemWorkflowConstant.DMS_CREATE_SCANNED_UDF_DOCUMENT)) { //* document profile
          SysUserDefinedIndexDAObject profileDAO = new SysUserDefinedIndexDAObject(sessionContainer, conn);
          List profileList = profileDAO.getListByStatus(GlobalConstant.RECORD_STATUS_ACTIVE);
          return profileList;
        } else if (workflowCategoryID == Integer.parseInt(SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM)) {
          FormRecordDAObject formDAO = new FormRecordDAObject(sessionContainer, conn);
          List formRecordList = formDAO.getFormRecordByStatus(FormRecord.FORM_STATUS_RELEASED);
          return formRecordList;
        } else if (workflowCategoryID == Integer.parseInt(SystemWorkflowConstant.FMB_SUBMISSION_BY_GROUP)) {
          FormGroupDAObject formGroupDAO = new FormGroupDAObject(sessionContainer, conn);
          List formGroupList = formGroupDAO.getFullList();
          return formGroupList;
        }            
      }catch(Exception e){            
          throw new Exception(e);        
      }                
      return tempList;
    }
    private List getBindWithSelectList(Integer wrokflowRecordID){
      List tempList = new ArrayList();
      try{
        MtmWorkflowRecordObjectLinkDAObject linkDAO = new MtmWorkflowRecordObjectLinkDAObject(sessionContainer, conn);

        //* get any existing workflowRecordObjectLink
        if (wrokflowRecordID!=null){
            tempList = linkDAO.getListByWorkflowRecordID(workflowRecordID);
        }
        return tempList;
      }catch(Exception e){            
        //throw new Exception(e);        
    } 
      return tempList;
      
    }
    private Object getStepInfoByWorkflowIDAndStepSeq(){
      AbstractBaseObject stepInfo = null;
      try{
        Integer stepSeq = TextUtility.parseIntegerObj(request.getParameter("stepSeq"));
        WorkflowStepDAObject workflowStepDAObject = new WorkflowStepDAObject (sessionContainer,conn);
        Integer ID = workflowStepDAObject.getStepIDByWorkflowIDAndStepSeq(workflowRecordID, stepSeq);
        WorkflowRetrievalManager retrievalManager = new WorkflowRetrievalManager(sessionContainer, conn);
      	WorkflowRecordDAObject recordDAO = new WorkflowRecordDAObject(sessionContainer, conn);
      	WorkflowRecord wfRecord = (WorkflowRecord) recordDAO.getObjectByID(new Integer(request.getParameter("workflowRecordID")));
      	//request.setAttribute("workflowRecord", wfRecord);
      
      	Integer groupID = wfRecord.getWorkflowGroupID();
        if(Utility.isEmpty(ID)||Utility.isEmpty(groupID)){
          return null;   
        }
      	stepInfo = retrievalManager.getWorkflowStepInfo(ID, groupID);
      
      	//stepInfo.setFormData(data);
        }catch(Exception e){            
          e.printStackTrace(System.out);        
        } 
      return stepInfo;   
    }
    
    private Object getWorkflowRecord(){
      WorkflowRecord wfRecord;
      try{        
        WorkflowRecordDAObject recordDAO = new WorkflowRecordDAObject(sessionContainer, conn);
        MtmWorkflowInterruptUserActorDAObject interruptActorDAO = new MtmWorkflowInterruptUserActorDAObject(sessionContainer, conn);
        wfRecord = (WorkflowRecord) recordDAO.getObjectByID(new Integer(request.getParameter("workflowRecordID")));
        List interruptUserActorList = interruptActorDAO.getListByWorkflowRecordID(new Integer(request.getParameter("workflowRecordID")));
        String interruptUserStr = "";
        
        for (int j = 0; j < interruptUserActorList.size(); j++) {
          MtmWorkflowInterruptUserActor interruptUserActor = (MtmWorkflowInterruptUserActor)interruptUserActorList.get(j);
          if(!Utility.isEmpty(interruptUserStr)){
            interruptUserStr+=";";
          }
          interruptUserStr+=interruptUserActor.getActorType()+"_"+interruptUserActor.getActorID().toString();
        }
        wfRecord.setInterruptSubmitter(interruptUserStr);
      }catch(Exception e){
        wfRecord = new WorkflowRecord();
        e.printStackTrace();        
        } 
      return wfRecord;   
    }
    private String getWorkflowChartByRecordID(){
      String workflowChart = "";
      String url = SystemParameterFactory.getSystemParameter(SystemParameterConstant.APPLICATION_BASE_URL);
      String[] urlMessage = url.split("/");
      String projectName = urlMessage[urlMessage.length-1];
      String filePath = SystemParameterFactory.getSystemParameter(SystemParameterConstant.WORKFLOW_ATTACHMENT_PHYSICAL_PATH)+"/"+projectName+"/"+request.getParameter("workflowRecordID")+".xml";
      try{        
        File file = new File(filePath);
        if(!file.exists()){
          return null;  
        }
        FileReader fileReader = new FileReader(new File(filePath));
        BufferedReader BR
               = new BufferedReader(new FileReader(filePath));
        String str;
        while((str=BR.readLine())!=null){
          workflowChart += str;
        }
      }catch(Exception e){
      e.printStackTrace(System.out);
      } 
      return workflowChart;   
    }
    
    private String getNextStepSeq(){
      Integer nextStepSeq = null;
      try{
        Integer workflowRecordID = TextUtility.parseIntegerObj(request.getParameter("workflowRecordID"));
        WorkflowStepDAObject workflowStepDAObject = new WorkflowStepDAObject (sessionContainer,conn);
        nextStepSeq = workflowStepDAObject.getNextStepSeqNumber(workflowRecordID);
      }catch(Exception e){
        e.printStackTrace(System.out);
      }
      return nextStepSeq.toString();
    }
    
    private String[] getResouce(){
      String locale = request.getParameter("LOCALE");
      java.util.Locale newLocale = Utility.getLocaleByString(locale);      
      sessionContainer.setLocale(newLocale);
      String[] resouce = new String[300];
      String[] resouceCode = new String[300];
      //workflow group tree
      resouceCode[0]="common.label.new";
      resouceCode[1]="common.label.edit"; 
      resouceCode[2]="workflow.label.workflow_routine";
      resouceCode[3]="dms.label.delete";
      resouceCode[4]="workflow.applet.setup";
      resouceCode[5]="workflow.applet.add";
      resouceCode[6]="contact.label.remove";
      //workflow record
      resouceCode[10]="workflow.label.workflow_information";
      resouceCode[11]="workflow.label.workflow_code";
      resouceCode[12]="workflow.label.workflow_version";
      resouceCode[13]="workflow.label.category";
      resouceCode[14]="workflow.label.bind_with";
      resouceCode[15]="workflow.label.workflow_group";
      resouceCode[16]="workflow.label.effective_period";
      resouceCode[17]="common.label.period_to";
      resouceCode[18]="workflow.label.workflow_record_enable_interrupt";
      resouceCode[19]="workflow.label.workflow_interrupt_approval";
      resouceCode[20]="workflow.label.description";
      resouceCode[21]="workflow.label.status";
      resouceCode[22]="common.options.status_P";
      resouceCode[23]="common.options.status_R";
      resouceCode[24]="workflow.applet.save";
      resouceCode[25]="workflow.applet.close";
      resouceCode[26]="workflow.label.workflow_record_enable_interrupt";
      resouceCode[27]="workflow.label.workflow_interrupt_approval";
      resouceCode[28]="setup.label.permission";
      resouceCode[29]="form.label.upload_location";
      
      
      
      
      //    Edtior
      resouceCode[30]="common.label.edit";
      resouceCode[31]="workflow.applet.remove";
      resouceCode[32]="workflow.applet.lock";
      resouceCode[33]="workflow.applet.new_step";
      resouceCode[34]="workflow.applet.create_todo_route";
      resouceCode[35]="workflow.applet.create_yes_route";
      resouceCode[36]="workflow.applet.create_no_route";
      resouceCode[37]="workflow.applet.create_approved_route";
      resouceCode[38]="workflow.applet.create_rejected_route";
      resouceCode[39]="workflow.applet.create_custom_route";
      resouceCode[40]="workflow.applet.create_form_value_driven";
      resouceCode[41]="workflow.applet.create_auto_task_route";
      
      resouceCode[45]="workflow.applet.undo";
      resouceCode[46]="workflow.applet.redo";
      resouceCode[47]="workflow.applet.copy";
      resouceCode[48]="workflow.applet.paste";
      resouceCode[49]="workflow.applet.cut";
      resouceCode[50]="workflow.applet.delete";
      resouceCode[51]="workflow.applet.zoomin";
      resouceCode[52]="workflow.applet.zoomout";
      resouceCode[53]="workflow.applet.group";
      resouceCode[54]="workflow.applet.ungroup";
      resouceCode[55]="workflow.applet.tofront";
      resouceCode[56]="workflow.applet.toback";
      resouceCode[57]="workflow.applet.layout";
      //stepinfo
      resouceCode[70]="workflow.label.rule_desc";
      resouceCode[71]="workflow.label.priority";
      resouceCode[72]="workflow.label.notify_by_system";
      resouceCode[73]="workflow.label.notify_by_mail";
      resouceCode[74]="workflow.label.notify_all_task_completed";
      resouceCode[75]="workflow.label.notify_owner_task_arrived";
      resouceCode[76]="workflow.label.notify_owner_task_overdue";
      resouceCode[77]="workflow.label.notify_all_task_overdue";
      resouceCode[78]="common.priority.label_1";
      resouceCode[79]="common.priority.label_2";
      resouceCode[80]="common.priority.label_3";
      resouceCode[81]="workflow.label.step_seq";
      resouceCode[82]="workflow.label.step_name";
      resouceCode[83]="workflow.label.description";
      resouceCode[84]="workflow.label.step_type";
      resouceCode[85]="workflow.label.step_type_S";
      resouceCode[86]="workflow.label.step_status_G";
      resouceCode[87]="workflow.label.step_status_A";
      resouceCode[88]="workflow.label.step_status_R";
      resouceCode[89]="workflow.label.step_status_F";
      resouceCode[90]="workflow.label.step_status_T";
      resouceCode[91]="workflow.label.owner";
      resouceCode[92]="workflow.label.dynamic_assign";
      resouceCode[93]="common.label.all";
      resouceCode[94]="common.label.none";
      resouceCode[95]="setup.label.user_accounts";
      resouceCode[96]="setup.label.user_groups";
      resouceCode[97]="setup.label.user_roles";
      resouceCode[98]="workflow.label.submitter";
      resouceCode[99]="workflow.label.report_to";
      resouceCode[100]="workflow.label.previous_task_owner";
      resouceCode[101]="workflow.label.report_to_of_previous_task";
      resouceCode[102]="workflow.label.previous_action_taker";
      resouceCode[103]="workflow.label.filter_by";
      resouceCode[104]="workflow.label.bind_with";
      resouceCode[105]="common.label.edit";
      resouceCode[106]="dms.label.permission_R";
      resouceCode[107]="workflow.label.workflow_rule";
      resouceCode[108]="workflow.label.due_date";
      resouceCode[109]="workflow.label.not_applicable";
      resouceCode[110]="workflow.label.days_after_task_arrival";
      resouceCode[112]="workflow.label.allow_assign_due_date";
      resouceCode[113]="common.label.mandatory";
      resouceCode[114]="workflow.label.action_after_due_date";
      resouceCode[115]="common.options.select_menu.select_one";
      resouceCode[116]="workflow.label.priority_escalation_rule";
      resouceCode[117]="workflow.label.allow_stop";
      resouceCode[118]="common.label.yes";
      resouceCode[119]="common.label.no";
      resouceCode[120]="workflow.label.notification";
      resouceCode[121]="workflow.label.action_after_due_K";
      resouceCode[122]="workflow.label.action_after_due_C";
      resouceCode[123]="workflow.label.action_after_due_A";
      resouceCode[124]="workflow.label.action_after_due_R";
      resouceCode[125]="workflow.label.action_after_due_S";
      resouceCode[126]="workflow.label.action_after_due_O";
      resouceCode[127]="workflow.label.action_after_due_T";
      resouceCode[128]="workflow.label.action_after_due_F";
      resouceCode[129]="workflow.label.action_after_due_U";
      resouceCode[130]="setup.label.subject_type_G";
      resouceCode[131]="setup.label.subject_type_R";
      resouceCode[132]="staff.label.hierarchy_level_1";
      resouceCode[133]="staff.label.hierarchy_level_2";
      resouceCode[134]="staff.label.hierarchy_level_3";
      resouceCode[135]="staff.label.hierarchy_level_4";
      resouceCode[136]="staff.label.hierarchy_level_5";
      resouceCode[137]="staff.label.hierarchy_level_6";
      resouceCode[138]="staff.label.hierarchy_level_7";
      resouceCode[139]="staff.label.hierarchy_level_8";
      resouceCode[140]="staff.label.hierarchy_level_9";
      resouceCode[141]="staff.label.hierarchy_level_10";
      resouceCode[142]="workflow.applet.basic_info";
      resouceCode[143]="workflow.applet.other_info";
      resouceCode[144]="workflow.applet.common_step";
      resouceCode[145]="workflow.applet.other";
      resouceCode[146]="workflow.applet.none_of_above";
      resouceCode[147]="workflow.applet.custom_route";
      resouceCode[148]="workflow.label.step_type_E";
      resouceCode[149]="workflow.applet.advance_setting";
      resouceCode[150]="setup.label.special_actor";
      resouceCode[151]="workflow.label.step_type_A";
      resouceCode[152]="workflow.label.step_type_T";
      resouceCode[153]="workflow.label.step_type_E";
      resouceCode[154]="workflow.label.step_type_B";
      resouceCode[155]="workflow.label.step_type_F";
      resouceCode[156]="workflow.label.step_type_U";
      
      //custom window
      resouceCode[160]="workflow.label.route_name";
      //auto task
      resouceCode[161]="workflow.applet.auto_task_route";
      //PriorityRule
      resouceCode[163]="workflow.label.please_setup_priority_rule";
      resouceCode[164]="workflow.label.trigger_type";
      resouceCode[165]="workflow.label.trigger_point";
      resouceCode[166]="workflow.label.escalate_level";
      resouceCode[167]="workflow.label.notification_by";
      resouceCode[168]="workflow.label.after_task_arrived";
      resouceCode[169]="workflow.label.before_task_due_date";
      resouceCode[170]="workflow.label.days";
      resouceCode[171]="workflow.label.hours";
      resouceCode[172]="workflow.label.minutes";
      resouceCode[173]="alert.label.notification_E";
      resouceCode[174]="alert.label.notification_S";
      resouceCode[175]="workflow.label.possible_priority_rule";
      resouceCode[176]="workflow.label.workflow_and";
      resouceCode[177]="dms.label.field_detail";
      resouceCode[178]="workflow.message.trigger_point_is_required";
      resouceCode[179]="workflow.message.assign_to_is_required";
      resouceCode[180]="workflow.label.workflow_is_pending_for";
      resouceCode[181]="workflow.label.task_priority_changed";
      resouceCode[182]="workflow.label.task_pick_up_by_user";
      resouceCode[183]="workflow.label.task_completed_by_user";
      resouceCode[184]="workflow.label.task_completed";
      resouceCode[185]="wworkflow.label.workflow_is_stop";
      resouceCode[186]="workflow.label.task_over_due_date";
      resouceCode[187]="workflow.label.receipients";
      resouceCode[188]="workflow.label.notify";
      resouceCode[189]="workflow.label.notify_task_is_arrived";
      resouceCode[190]="workflow.label.notify_task_is_pending";
      resouceCode[191]="workflow.label.notify_task_priority_changed";
      resouceCode[192]="workflow.label.notify_task_is_Picked_Up_by_user";
      resouceCode[193]="workflow.label.notify_task_is_completed_by_user";
      resouceCode[194]="workflow.label.notify_task_is_completed";
      resouceCode[195]="workflow.label.notify_task_is_stoped";
      resouceCode[196]="workflow.label.before_task_due_date";
      resouceCode[197]="workflow.label.notify_task_is_overdue";
      resouceCode[198]="workflow.label.possible_notify_rule";
      resouceCode[250]="workflow.label.notify_select_owner";
      resouceCode[251]="workflow.label.assign_to";

      
      
      
      

      
      
      //message
            
      resouceCode[200]="worklfow.message.user_actor_required";
      resouceCode[201]="worklfow.applet.autotask_type_required";
      resouceCode[202]="worklfow.applet.step_not_saved";
      resouceCode[203]="worklfow.applet.todo_route_limit";
      resouceCode[204]="worklfow.applet.no_route_limit";
      resouceCode[205]="worklfow.applet.todo_route_allowed";
      resouceCode[206]="worklfow.applet.boolean_route_allowed";
      resouceCode[207]="worklfow.applet.approval_route_allowed";
      resouceCode[208]="worklfow.applet.custom_route_allowed";
      resouceCode[209]="worklfow.applet.session_expried";
      resouceCode[210]="workflow.applet.parent_mustbe_auto_task";
      try{
        for(int i=0;i<300;i++){
          if(resouceCode[i]!=null){
            resouce[i]=MessageResourcesFactory.getMessage(newLocale, resouceCode[i]);
          }
        }
        
      }catch(Exception e){
        e.printStackTrace(System.out);
      }
      return resouce;
    }
    
    private String getResouceByCode() throws Exception{
      //request.setCharacterEncoding("UTF-8");
      String code = request.getParameter("CODE");      
      String arg1 = request.getParameter("ARG1");
      //arg1 = new String(arg1.getBytes(),"UTF-8");
      Locale locale = sessionContainer.getSessionLocale();
      String resouce=MessageResourcesFactory.getMessage(locale, code, arg1);
      return resouce;
    }
    
    private String[] getActionRouteLable(){
      String[] routeLableCode=null;
      String[] routeLable=null;
      String actionClassName = null;
      Locale locale = sessionContainer.getSessionLocale();
      try{
        Integer actionID = TextUtility.parseIntegerObj(request.getParameter("ACTIONID"));
        WorkflowActionDAObject workflowActionDAObject = new WorkflowActionDAObject (sessionContainer,conn);
        WorkflowAction workflowAction = (WorkflowAction)workflowActionDAObject.getObjectByID(actionID);
//        actionClassName = workflowAction.getActionClassName();
//        Class actionClass = Class.forName(actionClassName);
//        Constructor constructor = actionClass.getConstructor(new Class[]{});
        WorkflowProcessor workflowProcessor= AutomaticTaskFactory.getInstance(workflowAction);//mod by greatwall for AutomaticTask
        int routeNum = workflowProcessor.getNumOfRoutine();
        routeLableCode = new String[routeNum];
        routeLable = new String[routeNum];
        for(int i=0;i<routeNum;i++){
          routeLableCode[i]=workflowProcessor.getLabelString(i);
          routeLable[i]=MessageResourcesFactory.getMessage(locale, routeLableCode[i]);
        }
      }catch(Exception e){
        e.printStackTrace(System.out);
      }
      return routeLable;
    }
    
    private List getFormList(List formElementList, List formRecordList){
      try{
        MtmWorkflowRecordObjectLinkDAObject objectLinkDAO = new MtmWorkflowRecordObjectLinkDAObject(sessionContainer,conn);
        FormRecordDAObject formRecordDAO = new FormRecordDAObject(sessionContainer,conn);
        FormPageDAObject formPageDAO = new FormPageDAObject(sessionContainer,conn);
        FormElementDAObject formElementDAO = new FormElementDAObject(sessionContainer,conn);
        MtmFormPageFormSectionDAObject pageSectionDAO = new MtmFormPageFormSectionDAObject(sessionContainer,conn);
        MtmFormSectionFormElementDAObject sectionElementDAO = new MtmFormSectionFormElementDAObject(sessionContainer,conn);
        
        Integer workflowRecordID = TextUtility.parseIntegerObj(request.getParameter("workflowRecordID"));
        //* get any existing workflowRecordObjectLink
        Integer formRecordID = null;
        boolean firstFrom = false;
        if(!Utility.isEmpty(workflowRecordID) ){
          List objectLinkList = objectLinkDAO.getListByWorkflowRecordID(workflowRecordID);
          for(int i=0; i<objectLinkList.size(); i++){
            MtmWorkflowRecordObjectLink tmpObjectLink = (MtmWorkflowRecordObjectLink)objectLinkList.get(i);
            if(GlobalConstant.OBJECT_TYPE_FORM.equals(tmpObjectLink.getObjectType())){            
              if(!firstFrom){
                formRecordID = tmpObjectLink.getObjectID();
                firstFrom=true;
              }
              FormRecord formRecord = (FormRecord)formRecordDAO.getObjectByID(tmpObjectLink.getObjectID());
              formRecordList.add(formRecord);
            }  
          }       
        
        }
        
        if(!Utility.isEmpty(formRecordID)){
          List formPageList = formPageDAO.getDetailListByFormRecordID(formRecordID);
          for(int j=0; j<formPageList.size(); j++){
            FormPage formPage = (FormPage)formPageList.get(j);
            List pageSectionList = pageSectionDAO.getListByPageID(formPage.getID());
            for (int k=0; k<pageSectionList.size(); k++){
              MtmFormPageFormSection pageSection = (MtmFormPageFormSection)pageSectionList.get(k);
              List sectionElementList = sectionElementDAO.getListBySectionID(pageSection.getSectionID());
              for(int n=0; n<sectionElementList.size(); n++){
                MtmFormSectionFormElement sectionElement = (MtmFormSectionFormElement)sectionElementList.get(n);
                FormElement formElement = (FormElement)formElementDAO.getObjectByID(sectionElement.getElementID());
                if(FormElementType.ELEMENT_TEXT.equals(formElement.getElementType()) ||
                   FormElementType.ELEMENT_TEXT_AREA.equals(formElement.getElementType()) ||
                   FormElementType.ELEMENT_DATE_PICKER.equals(formElement.getElementType()) ){
                  
                  formElement.setFormRecordID(formRecordID.toString());
                  formElement.setFormPageID(formPage.getID().toString());
                  formElement.setFormSectionID(pageSection.getSectionID().toString());
                  formElementList.add(formElement);
                }
              }
            }
          }
        }
      }catch(Exception e){            
        //throw new Exception(e);        
      } 
      return formElementList;      
    }
    
    private List getFormElementList(){
      List formElementList = new ArrayList();
      try{
        MtmWorkflowRecordObjectLinkDAObject objectLinkDAO = new MtmWorkflowRecordObjectLinkDAObject(sessionContainer,conn);
        FormRecordDAObject formRecordDAO = new FormRecordDAObject(sessionContainer,conn);
        FormPageDAObject formPageDAO = new FormPageDAObject(sessionContainer,conn);
        FormElementDAObject formElementDAO = new FormElementDAObject(sessionContainer,conn);
        MtmFormPageFormSectionDAObject pageSectionDAO = new MtmFormPageFormSectionDAObject(sessionContainer,conn);
        MtmFormSectionFormElementDAObject sectionElementDAO = new MtmFormSectionFormElementDAObject(sessionContainer,conn);
        
        Integer workflowRecordID = TextUtility.parseIntegerObj(request.getParameter("workflowRecordID"));
        //* get any existing workflowRecordObjectLink
        Integer formRecordID = TextUtility.parseIntegerObj(request.getParameter("formRecordID"));;
        boolean firstFrom = false;
        
        if(!Utility.isEmpty(formRecordID)){
          List formPageList = formPageDAO.getDetailListByFormRecordID(formRecordID);
          for(int j=0; j<formPageList.size(); j++){
            FormPage formPage = (FormPage)formPageList.get(j);
            List pageSectionList = pageSectionDAO.getListByPageID(formPage.getID());
            for (int k=0; k<pageSectionList.size(); k++){
              MtmFormPageFormSection pageSection = (MtmFormPageFormSection)pageSectionList.get(k);
              List sectionElementList = sectionElementDAO.getListBySectionID(pageSection.getSectionID());
              for(int n=0; n<sectionElementList.size(); n++){
                MtmFormSectionFormElement sectionElement = (MtmFormSectionFormElement)sectionElementList.get(n);
                FormElement formElement = (FormElement)formElementDAO.getObjectByID(sectionElement.getElementID());
                if(FormElementType.ELEMENT_TEXT.equals(formElement.getElementType()) ||
                   FormElementType.ELEMENT_TEXT_AREA.equals(formElement.getElementType()) ||
                   FormElementType.ELEMENT_DATE_PICKER.equals(formElement.getElementType()) ){
                  
                  formElement.setFormRecordID(formRecordID.toString());
                  formElement.setFormPageID(formPage.getID().toString());
                  formElement.setFormSectionID(pageSection.getSectionID().toString());
                  formElementList.add(formElement);
                }
              }
            }
          }
        }
      }catch(Exception e){            
        //throw new Exception(e);        
      } 
      return formElementList;      
    }

}
